package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Data struct {
	Message string `form:"message" binding:"required"` 
}

func showForm(c *gin.Context) {
	c.HTML(http.StatusOK, "index.html", gin.H{
		"Message": "",
	})
}

func handleSubmit(c *gin.Context) {
	var data Data
	
	if err := c.ShouldBind(&data); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "index.html", gin.H{
		"Message": data.Message, })
}

func main() {
	r := gin.Default()
	r.LoadHTMLGlob("templates/*")
	r.GET("/form", showForm)
	r.POST("/submit", handleSubmit)
    r.Run(":8050")
}